#include <bits/extc++.h>
#define int long long
using namespace std;

int t,n,m,a,c;

inline int read(){
	int s=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)){
		if(c=='-')f^=1;
		c=getchar();
	}
	while(isdigit(c)){
		s=(s<<1)+(s<<3)+(c^48);
		c=getchar();
	}
	return f==0?s:-s;
}

void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10|48);
}

signed main(){
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	n=read(),m=read();
	for(int i=1;i<=n;++i)
		a=read();
	int ans=0;
	for(int i=1;i<=m;++i){
		c=read();
		int t=1ll<<(int)ceil(log2(c));
		int cnt=(1+t)*t/2;
		ans^=(i*cnt);
	}
	string s;
	cin>>s;
	while(s.size()>1)cin>>s;
	t=read();
	while(t--){
		write(ans);
		puts("");
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
